import axios from 'axios'
import qs from 'qs'

// 角色操作*******************************
// 更改用户锁定状态
export function changeLockStatus (lockInfo) {
    return axios.put(`admin/user/lock/${lockInfo.userId}/${lockInfo.unlocked}`)
}

// 获取用户关键信息
export function listUserKeyInfo (queryInfo) {
    return axios.get(`admin/user`, {
        params: { queryInfo },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 分页获取用户关键信息
export function pageUserKeyInfo (queryInfo) {
    return axios.get(`admin/user/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            ids: queryInfo.ids,
            accounts: queryInfo.accounts,
            unlocked: queryInfo.unlocked,
            asc: queryInfo.asc,
            desc: queryInfo.desc
        },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 角色操作*******************************
// 获取角色信息
export function listRoleInfo (queryInfo) {
    return axios.get(`admin/role`, {
        params: { queryInfo },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 分页获取角色信息
export function pageRoleInfo (queryInfo) {
    return axios.get(`admin/role/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            ids: queryInfo.ids,
            names: queryInfo.names,
            enable: queryInfo.enable
        },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 添加角色
export function insertRole (roleInfo) {
    return axios.post(`admin/role`, roleInfo)
}

// 更新角色
export function updateRole (updateInfo) {
    return axios.put(`admin/role/${updateInfo.id}`, updateInfo)
}

// 删除角色
export function deleteRole (roleId) {
    return axios.delete(`admin/role/${roleId}`)
}

// 权限操作*******************************
// 获取权限列表
export function listPermission () {
    return axios.get(`admin/permission`)
}

// 分页获取权限列表
export function pagePermission (pageInfo) {
    return axios.get(`admin/permission/${pageInfo.page}/${pageInfo.size}`)
}

// 用户角色操作***************************
// 获取单个用户角色记录
export function getOneUserRole (userId) {
    return axios.get(`admin/user_role/${userId}`)
}

// 获取多个用户角色记录
export function listUserRole (queryInfo) {
    return axios.get(`admin/user_role`, { params: queryInfo })
}

// 分页获取多个用户角色记录
export function pageUserRole (queryInfo) {
    return axios.get(`admin/user_role/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            userIds: queryInfo.userIds,
            roleIds: queryInfo.roleIds,
            operateAreas: queryInfo.operateAreas,
            withSelf: queryInfo.withSelf,
            statuses: queryInfo.statuses,
            asc: queryInfo.asc,
            desc: queryInfo.desc
        },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 为用户赋予角色
export function insertUserRole (userRoleInfo) {
    return axios.post(`admin/user_role/${userRoleInfo.userId}/${userRoleInfo.roleId}`, {
        operateArea: userRoleInfo.operateArea,
        withSelf: userRoleInfo.withSelf,
        level: userRoleInfo.level,
        status: userRoleInfo.status,
        recoveryTime: userRoleInfo.recoveryTime,
        description: userRoleInfo.description
    })
}

// 修改用户赋予的角色
export function updateUserRole (updateInfo) {
    return axios.put(`admin/user_role/${updateInfo.userId}/${updateInfo.roleId}`, {
        operateArea: updateInfo.operateArea,
        withSelf: updateInfo.withSelf,
        level: updateInfo.level,
        status: updateInfo.status,
        recoveryTime: updateInfo.recoveryTime,
        description: updateInfo.description
    })
}

// 移除用户赋予的角色
export function deleteUserRole (deleteInfo) {
    return axios.delete(`admin/user_role/${deleteInfo.userId}/${deleteInfo.roleId}`)
}

// 角色权限操作***************************
// 获取单个角色权限记录
export function getOneRolePermission (roleId) {
    return axios.get(`admin/role_permission/${roleId}`)
}

// 获取多个用户角色记录
export function listRolePermission (queryInfo) {
    return axios.get(`admin/role_permission`, { params: queryInfo })
}

// 分页获取多个用户角色记录
export function pageRolePermission (queryInfo) {
    return axios.get(`admin/role_permission/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            roleIds: queryInfo.roleIds
        },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 为角色赋予权限
export function insertRolePermission (rolePermissionInfo) {
    return axios.post(`admin/role_permission/${rolePermissionInfo.roleId}/${rolePermissionInfo.permissionId}/${rolePermissionInfo.authorize}`)
}

// 修改角色赋予的权限
export function updateRolePermission (updateInfo) {
    return axios.put(`admin/role_permission/${updateInfo.roleId}/${updateInfo.permissionId}/${updateInfo.authorize}`)
}

// 移除用户赋予的角色
export function deleteRolePermission (deleteInfo) {
    return axios.delete(`admin/role_permission/${deleteInfo.roleId}/${deleteInfo.permissionId}`)
}

// 用户信息操作***************************
// 获取当前用户信息
export function currentUserInfo () {
    return axios.get(`user/info`)
}

// 修改当前用户信息
export function updateCurrentUserInfo (updateInfo) {
    return axios.put(`user/info`, updateInfo)
}

// 获取单个用户信息
export function getOneUserInfo (userId) {
    return axios.get(`user/info/${userId}`)
}

// 获取多个用户信息
export function listUserInfo (queryInfo) {
    return axios.get(`user/info/list`, {
        params: queryInfo,
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 分页获取多个用户信息
export function pageUserInfo (queryInfo) {
    return axios.get(`user/info/list/${queryInfo.page}/${queryInfo.size}`, {
        params: {
            ids: queryInfo.ids,
            nicknames: queryInfo.nicknames,
            asc: queryInfo.asc,
            desc: queryInfo.desc
        },
        paramsSerializer: params => {
            return qs.stringify(params, { indices: false })
        }
    })
}

// 关注操作*******************************
// 获取用户关注的用户
export function attentionUsers (userId) {
    return axios.get(`user/attention/${userId}`)
}

// 分页获取用户关注的用户
export function pageAttentionUsers (queryInfo) {
    return axios.get(`user/attention/${queryInfo.userId}/${queryInfo.page}/${queryInfo.size}`)
}

// 获取用户的粉丝
export function fans (userId) {
    return axios.get(`user/fans/${userId}`)
}

// 分页获取用户的粉丝
export function pageFans (queryInfo) {
    return axios.get(`user/fans/${queryInfo.userId}/${queryInfo.page}/${queryInfo.size}`)
}

// 关注用户
export function attentionUser (userId) {
    return axios.post(`user/attention/${userId}`)
}

// 取消关注用户
export function removeAttentionUser (userId) {
    return axios.delete(`user/attention/${userId}`)
}
